package com.burgeon.backend.EnterpriseWeChat.rest.EWEmployee;

import com.burgeon.backend.Rest.base.RESTBase;
import com.burgeon.backend.SHOPBACKEND.entity.vip.Employee;
import org.json.JSONArray;
import org.springframework.util.MultiValueMap;

import java.util.ArrayList;
import java.util.HashMap;

public class findEmployeeByStore extends RESTBase {

    private String ip;
    private String account;
    private String password;

    public findEmployeeByStore(String ip, String account, String password) {
        this.ip = ip;
        this.account = account;
        this.password = password;
    }

    /**
     * 发送并接收字符创
     */

    public ArrayList<Employee> getData(String store) throws Exception {
        String url = "http://"+ip+"/servlets/binserv/Rest";

        String str = RESULT(Data(store),url);

        JSONArray jsonArray = new JSONArray(str).getJSONObject(0).getJSONArray("rows");
        ArrayList<Employee> list = new ArrayList<>();

        for (int i=0;i<jsonArray.length();i++){
            Employee employee = new Employee();

            employee.setId(jsonArray.getJSONArray(i).getString(0));
            employee.setName(jsonArray.getJSONArray(i).getString(1));
            employee.setNO(jsonArray.getJSONArray(i).getString(2));

            list.add(employee);
        }

        return list;
    }

    private MultiValueMap Data(String store) {
        HashMap params = new HashMap();
        ArrayList columns = new ArrayList();//查询字段

        columns.add("ID");
        columns.add("NAME");
        columns.add("NO");

        params.put("columns", columns);
        params.put("table", "C_V_EMPLOYEE");//表名

        HashMap paramss = new HashMap();
        HashMap expr1 = new HashMap();
        expr1.put("column","ISACTIVE");
        expr1.put("condition","Y");
        HashMap expr2 = new HashMap();
        expr2.put("column","'C_STORE_ID;NAME'");
        expr2.put("condition","'="+store+"'");

        paramss.put("combine","and");
        paramss.put("expr1",expr1);
        paramss.put("expr2",expr2);

        params.put("params",paramss);
        return DATA("Query", params,account,password);
    }

    public static void main(String[] args) throws Exception {
        findEmployeeByStore g = new findEmployeeByStore("39.104.240.134:55321", "nea@burgeon.com.cn", "root55321");

        System.err.println(g.getData("新疆杉杉奥莱GXG"));

    }


}
